package com.sunny;

import java.util.Arrays;
import java.util.Collections;

/**
 * 给一个字符串，输出所能组成的所有字符串，考虑重复值
 */
public class Main {

    public static void main(String[] args) {

        char[] str = {'a','a','b','c','d'};
        dfs(str, 0);

    }

    public static void dfs(char[] str, int ind){

        if(ind == str.length){
            for(char c: str){
                System.out.print(c);
            }
            System.out.println();
        }

        for(int i=ind;i<str.length;i++){
            if(i != ind && str[i] == str[ind])
                continue;
            swap(str, i, ind);
            dfs(str, ind+1);
            swap(str, i, ind);
        }

    }

    public static void swap(char[] str, int a, int b){
        char tmp = str[a];
        str[a] = str[b];
        str[b] = tmp;
    }

}
